Vamos a hacer a ball ir a una posición aleatoria en el escenario.
Ve a y arrastra Random Integer en tu programa. Cambia el nombre de la variable (antes del signo igual) a x . Cambia el número a (-100 , 150 ) . Este comando elige al azar una coordenada x entre -100 y 150 , la cual se almacena en el nombre de la variable x .
To navigate the page using the TAB key, first press ESC to exit the code editor.
stage.set_background("halfcourt")
sprite = codesters.Sprite("player4")
sprite.go_to(215, -175)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
ball = codesters.Sprite("basketball")
t = codesters.Teacher()
try:
tval1 = t.get_parameters_for_function("randint")
except:
tval1 = "DNE"
try:
tval1b = x
except:
tval1b = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == [['-100', '150']], "Great Job!")
t1.add_failure(tval1 == [], "Did you add a random integer command?")
t1.add_failure(tval1 == [['1', '10']], "Did you change the numbers in the randint command?")
t1.add_creative(tval1 != [['1', '10']] and tval1 != [['-100', '150']], "Creative choice!")
t2 = TestObjective()
t2.add_success(tval1b != "DNE", "Great job!")
t2.add_failure(tval1b == "DNE", "Did you change the name of the random variable to x?")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
Run Code
Activity Submitted!
Submit Work
Next Activity
Stop Running Code
Show Chart
Show Console
Reset Code Editor
Codesters How To (opens in a new tab)